package com.manger.listener;

import com.manger.thread.CaseFilesFormatThread;
import com.manger.utils.ZipFileFilter;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;

public class ArrangeClickListener implements MouseListener {

    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("+++++++++++++整理案件++++++++++++++++++");


        //选择zip文件;
        String resourceDirPath = "";
        JFileChooser zipChooser = new JFileChooser();
        zipChooser.setBackground(Color.WHITE);
        zipChooser.setForeground(Color.WHITE);
        zipChooser.setDialogTitle("请选择需要整理的文件夹");
        zipChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        zipChooser.setAcceptAllFileFilterUsed(false); // 可选，禁用所有文件类型的过滤，只显示文件夹
       // zipChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
     //   zipChooser.setFileFilter(new ZipFileFilter()); // 应用文件过滤器
        int returnValue = zipChooser.showOpenDialog(null);
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            File selectedDirectory = zipChooser.getSelectedFile();
            resourceDirPath = selectedDirectory.getAbsolutePath();
        } else {
            System.out.println("没有选择压缩包!");
            return;
        }

        JFileChooser chooser = new JFileChooser();
        chooser.setBackground(Color.WHITE);
        chooser.setForeground(Color.WHITE);
        chooser.setDialogTitle("请选择整理结果文件夹");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false); // 可选，禁用所有文件类型的过滤，只显示文件夹

        // 显示对话框并获取用户的选择结果
         returnValue = chooser.showOpenDialog(null); // 使用 null 表示无父组件，或者传入一个 JFrame 或 JPanel 实例作为父组件
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            File selectedDirectory = chooser.getSelectedFile();
            CaseFilesFormatThread caseFilesFormatThread = new CaseFilesFormatThread(selectedDirectory.getAbsolutePath(),resourceDirPath);
            caseFilesFormatThread.start();
        } else {
            System.out.println("没有选择文件夹!");
        }
    }

    @Override
    public void mouseExited(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }
}
